// 2022年11月11日 星期五 15:30

export class Time {
   static timeList = (time?: string): Array<number> => {
      const current: Date = time?new Date(time):new Date();
      const YYYY = current.getFullYear();
      const MM = current.getMonth() + 1;
      const DD = current.getDate();
      const hh = current.getHours();
      const mm = current.getMinutes();
      const ss = current.getSeconds();
      const WEEK = current.getDay()
      return [YYYY, MM, DD, hh, mm, ss, WEEK];
   };

   static cWeek = [ "日","一", "二", "三", "四", "五", "六"];

   static getFormatTime = (format: string, time?: string): string => {
      const [YYYY, MM, DD, hh, mm, ss, WEEK] = this.timeList(time);
      const result = format
         .replace("YYYY", `${+YYYY}`)
         .replace("MM", `${+MM}`)
         .replace("DD", `${+DD}`)
         .replace("hh", `${+hh}`)
         .replace("mm", `${mm>9?mm:0+mm}`)
         .replace("ss", `${+ss}`)
         .replace("WEEK", `星期${this.cWeek[WEEK]}`);
      return result;
   };
}
